#override("css")
<link href="#springUrl('/static/css/bootstrap.min.css')" rel="stylesheet">
#end

#override("body")
<body class="white-bg">
<form id="baseForm"  class="form-horizontal m-t" autocomplete="off" data-validator-option="{timely:2, theme:'simple_bottom', focusCleanup:true}">
	<div class="wrapper wrapper-content form-item">
		<div class="panel panel-default">
			<div class="row">
				<input type="hidden" name="id" value="$!{sysUser.id}">
				<input type="hidden" name="userPwd" value="$!{sysUser.userPwd}">

				<br />
				<div class="col-xs-6">
					<div class="form-group">
						<label class="col-md-4 control-label">所属机构:</label>
						<div class="col-md-6">
							<input type=text id="executeOrgName" name="orgName" class="form-control" value="$!{sysUser.orgName}" onclick="showOrg()" readonly="readonly" data-rule="上级机构:required">
							<input type="hidden" id="executeOrgNo" name="orgNo" value="$!{sysUser.orgNo}">
						</div>
					</div>
				</div>
				<div class="col-xs-6">
					<div class="form-group">
						<label class="col-md-4 control-label">用户名:</label>
						<div class="col-md-6">
							<input type="text" class="form-control" name="userName" value="$!{sysUser.userName}" placeholder="请输入用户名" data-rule="用户名:required;length(1~30)">
						</div>
					</div>
				</div>
				<div class="col-xs-6">
					<div class="form-group">
						<label class="col-md-4 control-label">用户编号:</label>
						<div class="col-md-6">
							<input type="text" class="form-control" name="userCode" value="$!{sysUser.userCode}" placeholder="请输入用户编号" data-rule="用户编号:required;length(1~16)">
						</div>
					</div>
				</div>
				<div class="col-xs-6">
					<div class="form-group">
						<label class="col-md-4 control-label">核心客户号:</label>
						<div class="col-md-6">
							<input type="text" class="form-control" name="mainCorpNo" value="$!{sysUser.mainCorpNo}" placeholder="请输入核心客户号" data-rule="核心客户号:required;length(1~32)">
						</div>
					</div>
				</div>
				<div class="col-xs-6">
					<div class="form-group">
						<label class="col-md-4 control-label">用户状态:</label>
						<div class="col-md-6">
							<select class="form-control" name="state" data-rule="用户状态:required">
								<option value="0">正常</option>
								<option value="1">锁定</option>
							</select>
						</div>
					</div>
				</div>
				<div class="col-xs-6">
					<div class="form-group">
						<label class="col-md-4 control-label">性别:</label>
						<div class="col-md-6">
							<select class="form-control" name="sex" data-rule="用户状态:required">
								<option value="0">男</option>
								<option value="1">女</option>
							</select>
						</div>
					</div>
				</div>
				<div class="col-xs-6">
					<div class="form-group">
						<label class="col-md-4 control-label">联系电话:</label>
						<div class="col-md-6">
							<input type="text" class="form-control" name="phone" value="$!{sysUser.phone}" placeholder="请输入联系电话" data-rule="联系电话:length(1~14)">
						</div>
					</div>
				</div>
				<div class="col-xs-6">
					<div class="form-group">
						<label class="col-md-4 control-label">身份证号码:</label>
						<div class="col-md-6">
							<input type="text" class="form-control" name="idCode" value="$!{sysUser.idCode}" placeholder="请输入身份证号码" data-rule="身份证号码:length(1~18)">
						</div>
					</div>
				</div>
				<div class="col-xs-6">
					<div class="form-group">
						<label class="col-md-4 control-label">是否可登录:</label>
						<div class="col-md-6">
							<select class="form-control" name="loginFlag" data-rule="是否可登录:required">
								<option value="0">是</option>
								<option value="1">否</option>
							</select>
						</div>
					</div>
				</div>
				<div class="col-xs-6">
					<div class="form-group">
						<label class="col-md-4 control-label">排序:</label>
						<div class="col-md-6">
							<input type="number" class="form-control" name="sort" value="$!{sysUser.sort}" placeholder="请输入序号" data-rule="required:integer[+]:length[~3];sort">
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</form>
</body>
#end

#override("js")
<script type="text/javascript">
	// 页面加载的时候调用的js
	$(function () {
		if ("$!{action}" == "doView") {
			$('input,select,textarea,checkbox,radio', $('form[id="baseForm"]')).attr('disabled', true);
		}
	});

	// 初始化表单验证及提交
	$("#baseForm").validator({
		focusCleanup: true,
		// 验证成功
		valid: function (form) {
			var me = this;
			// 提交表单之前，hold住表单，防止重复提交
			me.holdSubmit();

			$.ajax({
				url: "#springUrl('/sys/sysUser/doEdit')",
				data: $(form).serialize(),
				type: "POST",
				success: function (data) {
					if (data.success) {
						parent.refreshTable();
						parent.layer.alert('处理数据成功', {icon: 1}, function () {
							parent.layer.closeAll();
						});
					} else {
						parent.layer.alert(data.message, {icon: 2}, function (index) {
							//失败,提交表单成功后,释放hold,如果不释放hold,就变成了只能提交一次的表单
							me.holdSubmit(false);
							parent.layer.close(index);
						});
					}
				}
			});
		}
	});
	// 调用方法实现保存
	function save() {
		// 手工触发表单验证
		$("#baseForm").trigger('validate');
	}
</script>

<script type="text/javascript">
	// 转到显示选择机构类型树页面
	function showOrg() {
		var orgNo = $("#orgNo").val();
		var url = "#springUrl('/sys/sysUser/toTree?orgNo="+orgNo+"')";
		layer_show_btn("选择用户所属机构", url, 400, null);
	}

	// 根据选择的机构编号,获取该机构下的用户的最大sort值并+1
	function getMaxSortByPNo(orgNo) {
		if(isNull(orgNo)) return;

		$.ajax({
			url:"#springUrl('/sys/sysUser/getMaxSortByOrgNo/')" + orgNo,
			data: "json",
			success : function(data) {
				if (data.success) {
					$("input[name='sort']").val(data.data);
				} else {
					$("input[name='sort']").val(1);
				}
			}
		});
	}
</script>
#end
#extends("/common/base.html")